<!------------------------ Pdf Handling Code Begin ------------------------>        
<script>
var in_frame = false;

function show_waiting() {
    var h =$("body").height(); 
    var w =$("body").width()+16;  
    $("#mask_bg").css({width:w,height:h,top:0,left:0}); 
    $("#mask_bg").css('display','block');
    var y_pos =  in_frame ? 150 : (h-100)/2;
    $("#dialog").css({top:y_pos,left:(w-300)/2}); 
    $("#dialog").show('slow');
}

function hide_waiting() {
    $("#mask_bg").hide();
    $("#dialog").hide();
    $('#btn_send_mail').val('发送');
    $('#btn_send_mail').attr('disabled', false); 
    $('#btn_close').attr('disabled', false);    
}

var card_id = 0;  
var form_ids = "";
var check_pdf_timer = null;     
var operation = "download";

function download_pdf(id) {
    if(confirm('确认要进行签证表格下载吗？')) {
        operation = "download";
        card_id = id;
        $("#dialog").html($("#dl_content").html());
        show_waiting();
        generate_pdf();
    }
}

function send_to_mail(id) {
    operation = "send_mail";  
    card_id = id;
    $("#dialog").html($("#mail_content").html());
    show_waiting();
}

function do_send_mail() {
    if($('#user_mail').val() == "") {
        alert('请输入接收签证表格的邮箱！');
        return false;
    }
    if(confirm('确认将签证表格发送到['+$('#user_mail').val()+']邮箱吗？')) {
        generate_pdf(); 
        $('#btn_send_mail').val('处理中...');
        $('#btn_send_mail').attr('disabled', true); 
        $('#btn_close').attr('disabled', true); 
    }
}

function make_pdf_to_zip() {
    //alert(form_ids)
    $.get("<?=base_url()?>user/make_pdf_to_zip/"+card_id+"/"+form_ids, function(str){
        //alert(str)
        eval('var data = '+str);
        if(data['result'] == 'ok') {
            if(operation == "download") {
               $('#free_frame').attr('src', "<?=base_url()?>user/download_forms/"+card_id); 
               hide_waiting(); // 下载时，由于页面是输出流，所以只能先调用此方法;
            } else if(operation == "send_mail") {
               $('#free_frame').attr('src', "<?=base_url()?>user/send_mail_forms/"+card_id+"?user_mail="+encodeURI($('#user_mail').val())); 
               // 发送邮件时，在页面加载完成后，再调用父页的 hide_waiting();
            }
        }
    });
}

function invoke_java_servive(json_data) {
    <? if($_ENV['COMPUTERNAME'] == "zhouxuan") {?>  
        var service_url = "http://192.168.1.108:8082/test/download.php"; // testing 
    <? } else {?>
        var service_url = "http://210.75.192.148:9090/javaprduct/servlet/Onfile";  // production
    <? } ?>   
    $.getJSON(service_url+"?clients="+encodeURI(json_data)+"&jsoncallback=?", function(data){ 
        //alert(data.result);
        //alert(data.msg);
        make_pdf_to_zip(); // 调用java端的pdf生成服务完成后，再进行后续动作(压缩成zip包后下载或发邮件)
    });
}

</script>
</div>
<iframe id='free_frame' name='free_frame' width="1" height="0" style="display:none"></iframe>
<link rel="stylesheet" type="text/css" href="css/dialog.css" />     
<div id="mask_bg"></div>  
<div id="dialog"></div>
<div id="dl_content" style="display: none;">
    <img src="css/images/loading.gif"><br>
    <div class="text" id="dialog_text">后台正在处理中，请耐心等待...</div>
</div> 
<div id="mail_content" style="display: none;">
    <b>请确认签证表格的接收邮箱：</b><input type="text" size=30 id="user_mail" value="<?echo $_SESSION['user_mail']?>" style="height:23px;font-size:16px;font-family:arial;color:#006F00"><br>
    <input type="button" value="发送" id="btn_send_mail" onclick="do_send_mail()">　<input type="button" id="btn_close" value="关闭" onclick="hide_waiting()">
</div>
<!------------------------ Pdf Handling Code End ------------------------>         
